import { Col, Spin } from "antd";
import { Layout, Row } from "antd";
import React, { useEffect } from "react";
import AlertNeedLogin from "../components/alert-need-login";
const { Content, Footer } = Layout;
import { useSession } from "next-auth/react";
import { useRouter } from "next/router";

export default function Index() {
  const { data: session, status } = useSession();
  const router = useRouter();
  useEffect(() => {
    if (session && status === "authenticated") {
      router.push("/home");
    }
  });
  return (
    <Layout style={{ minHeight: "100vh" }}>
      <Row justify="center" align="middle" style={{ minHeight: "100vh" }}>
        {status === "loading" && <Spin />}
        {status === "unauthenticated" && <AlertNeedLogin />}
        <Col span={24}>
          <Footer style={{ textAlign: "center" }}>
            ©2022 Created by Yingjie Shang
          </Footer>
        </Col>
      </Row>
    </Layout>
  );
}
